/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package nxtmodel2.impl;

import java.util.Collection;

import nxtmodel2.FlowChartNxt;
import nxtmodel2.NxtElement;
import nxtmodel2.NxtRobot;
import nxtmodel2.Nxtmodel2Package;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Nxt Robot</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link nxtmodel2.impl.NxtRobotImpl#getElements <em>Elements</em>}</li>
 *   <li>{@link nxtmodel2.impl.NxtRobotImpl#getName <em>Name</em>}</li>
 *   <li>{@link nxtmodel2.impl.NxtRobotImpl#getFlowChart <em>Flow Chart</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NxtRobotImpl extends EObjectImpl implements NxtRobot {
	/**
	 * The cached value of the '{@link #getElements() <em>Elements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElements()
	 * @generated
	 * @ordered
	 */
	protected EList<NxtElement> elements;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getFlowChart() <em>Flow Chart</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFlowChart()
	 * @generated
	 * @ordered
	 */
	protected FlowChartNxt flowChart;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected NxtRobotImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Nxtmodel2Package.Literals.NXT_ROBOT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NxtElement> getElements() {
		if (elements == null) {
			elements = new EObjectContainmentEList<NxtElement>(NxtElement.class, this, Nxtmodel2Package.NXT_ROBOT__ELEMENTS);
		}
		return elements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Nxtmodel2Package.NXT_ROBOT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FlowChartNxt getFlowChart() {
		return flowChart;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetFlowChart(FlowChartNxt newFlowChart, NotificationChain msgs) {
		FlowChartNxt oldFlowChart = flowChart;
		flowChart = newFlowChart;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Nxtmodel2Package.NXT_ROBOT__FLOW_CHART, oldFlowChart, newFlowChart);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFlowChart(FlowChartNxt newFlowChart) {
		if (newFlowChart != flowChart) {
			NotificationChain msgs = null;
			if (flowChart != null)
				msgs = ((InternalEObject)flowChart).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - Nxtmodel2Package.NXT_ROBOT__FLOW_CHART, null, msgs);
			if (newFlowChart != null)
				msgs = ((InternalEObject)newFlowChart).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - Nxtmodel2Package.NXT_ROBOT__FLOW_CHART, null, msgs);
			msgs = basicSetFlowChart(newFlowChart, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Nxtmodel2Package.NXT_ROBOT__FLOW_CHART, newFlowChart, newFlowChart));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Nxtmodel2Package.NXT_ROBOT__ELEMENTS:
				return ((InternalEList<?>)getElements()).basicRemove(otherEnd, msgs);
			case Nxtmodel2Package.NXT_ROBOT__FLOW_CHART:
				return basicSetFlowChart(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Nxtmodel2Package.NXT_ROBOT__ELEMENTS:
				return getElements();
			case Nxtmodel2Package.NXT_ROBOT__NAME:
				return getName();
			case Nxtmodel2Package.NXT_ROBOT__FLOW_CHART:
				return getFlowChart();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Nxtmodel2Package.NXT_ROBOT__ELEMENTS:
				getElements().clear();
				getElements().addAll((Collection<? extends NxtElement>)newValue);
				return;
			case Nxtmodel2Package.NXT_ROBOT__NAME:
				setName((String)newValue);
				return;
			case Nxtmodel2Package.NXT_ROBOT__FLOW_CHART:
				setFlowChart((FlowChartNxt)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Nxtmodel2Package.NXT_ROBOT__ELEMENTS:
				getElements().clear();
				return;
			case Nxtmodel2Package.NXT_ROBOT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case Nxtmodel2Package.NXT_ROBOT__FLOW_CHART:
				setFlowChart((FlowChartNxt)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Nxtmodel2Package.NXT_ROBOT__ELEMENTS:
				return elements != null && !elements.isEmpty();
			case Nxtmodel2Package.NXT_ROBOT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case Nxtmodel2Package.NXT_ROBOT__FLOW_CHART:
				return flowChart != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //NxtRobotImpl
